﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Renci.iRods.Studio.Modules.Explorer.Models
{
    public class UserModel : MetadataItemModel
    {
        private Renci.iRods.Data.User _user;

        [DisplayName("ID"), ReadOnly(true), Browsable(true)]
        public long ID { get; internal set; }

        [DisplayName("Name"), ReadOnly(true), Browsable(true)]
        public string Name { get; internal set; }

        [DisplayName("Type"), ReadOnly(true), Browsable(true)]
        public string Type { get; internal set; }

        [DisplayName("Zone"), ReadOnly(true), Browsable(true)]
        public string Zone { get; internal set; }

        [DisplayName("Info"), ReadOnly(true), Browsable(true)]
        public string Info { get; internal set; }

        [DisplayName("Comment"), ReadOnly(true), Browsable(true)]
        public string Comment { get; internal set; }

        [DisplayName("Created Time"), ReadOnly(true), Browsable(true)]
        public DateTime CreatedTime { get; internal set; }

        [DisplayName("Modified Time"), ReadOnly(true), Browsable(true)]
        public DateTime ModifiedTime { get; internal set; }

        private IEnumerable<MetadataModel> _metadata;
        public override IEnumerable<MetadataModel> Metadata
        {
            get
            {
                if (this._metadata == null)
                {
                    this._metadata = from m in this._user.MetaData
                                     select new MetadataModel(m.ID, m.Namespace, m.Name, m.Value, m.Unit);
                }

                return this._metadata;
            }
        }


        internal UserModel(IRodsConnection connection, Renci.iRods.Data.User user)
            : base(connection)
        {
            this._user = user;
            this.ID = this._user.Id;
            this.Name = this._user.Name;
            this.Type = this._user.Type;
            this.Zone = this._user.Zone;
            this.Info = this._user.Info;
            this.Comment = this._user.Comment;
            this.CreatedTime = this._user.CreatedTime;
            this.ModifiedTime = this._user.ModifiedTime;
        }


    }
}
